package com.example.demo.reflect;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

/**
 * @desc:
 * @author: fuxiang
 * @date: 2018/3/5 16:37
 */
public class FieldsTestMain {
    public static void main(String[] args) throws Exception {
        Class clazz = Class.forName("com.example.demo.reflect.Student");
        System.out.println("获取全部字段");
        Field[] declaredFields = clazz.getDeclaredFields();
        for(Field field:declaredFields){
            System.out.println(field);
        }
        Field f = clazz.getField("name");
        System.out.println(f);
        Object o = clazz.getConstructor().newInstance();//产生Student对象--》Student stu = new Student();
        Student student= (Student) o;
        student.setName("hhhhh");
        System.out.println(student.getName());
        List<String> list=new ArrayList<>();
        list.add("1");
        list.add("2");
        list.add("3");
        list.forEach(System.out::println);
    }
}
